﻿<!--
	Copyright 2012 Douglas Harber

    This file is part of TSW.CombatTracker.

    TSW.CombatTracker is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    TSW.CombatTracker is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with TSW.CombatTracker.  If not, see <http://www.gnu.org/licenses/>.
-->
<UserControl x:Class="TSW.CombatTracker.CombatDisplay"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:l="clr-namespace:TSW.CombatTracker;assembly="
			 xmlns:w="clr-namespace:System.ComponentModel;assembly=WindowsBase"
			 xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
			 FontSize="9"
			 Background="Black" Foreground="White"
			 mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="500">
	<UserControl.Resources>
		<CollectionViewSource x:Key="CharactersSource"
							  Source="{Binding Characters}"
							  Filter="CharactersSource_Filter">
			<CollectionViewSource.SortDescriptions>
				<w:SortDescription Direction="Descending" PropertyName="IsYou" />
				<w:SortDescription Direction="Descending" PropertyName="Offensive_DPS" />
				<w:SortDescription Direction="Ascending" PropertyName="Name" />
			</CollectionViewSource.SortDescriptions>
		</CollectionViewSource>

		<Style x:Key="ColumnsHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
			<Setter Property="Background" Value="Transparent" />
			<Setter Property="Foreground" Value="White" />
		</Style>

		<DataTemplate x:Key="AttackAttacksCell">
			<TextBlock Text="{Binding Path=Hits.TotalAttacks, StringFormat=N0}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="AttackDamageCell">
			<TextBlock Text="{Binding Path=Hits.TotalDamage, StringFormat=N0}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="AttackDmgPerHitCell">
			<TextBlock Text="{Binding Path=Hits.DamagePerHit, StringFormat=N2}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="AttackDPSCell">
			<TextBlock Text="{Binding Path=Hits.DPS, StringFormat=N1}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="AttackDPMCell">
			<TextBlock Text="{Binding Path=Hits.DPM, StringFormat=N1}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="AttackPercentCritCell">
			<TextBlock Text="{Binding Path=Hits.CritPercent, StringFormat={}{0:N1}%}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="AttackPercentPenetratedCell">
			<TextBlock Text="{Binding Path=Hits.PenetratedPercent, StringFormat={}{0:N1}%}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="AttackPercentTotalCell">
			<TextBlock Text="{Binding PercentOfTotalDamage, StringFormat={}{0:N1}%}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<GridViewColumnCollection x:Key="AttackTypesColumns">
			<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="110" />
			<GridViewColumn Header="Hits" CellTemplate="{StaticResource AttackAttacksCell}" Width="50" />
			<GridViewColumn Header="Damage" CellTemplate="{StaticResource AttackDamageCell}" Width="65" />
			<GridViewColumn Header="Dmg/Hit" CellTemplate="{StaticResource AttackDmgPerHitCell}" Width="45" />
			<GridViewColumn Header="DPS" CellTemplate="{StaticResource AttackDPSCell}" Width="45" />
			<!--<GridViewColumn Header="DPM" CellTemplate="{StaticResource AttackDPMCell}" Width="45" />-->
			<GridViewColumn Header="% Crit" CellTemplate="{StaticResource AttackPercentCritCell}" Width="45" />
			<GridViewColumn Header="% Pen" CellTemplate="{StaticResource AttackPercentPenetratedCell}" Width="45" />
			<GridViewColumn Header="% Total" CellTemplate="{StaticResource AttackPercentTotalCell}" Width="45" />
		</GridViewColumnCollection>

		<DataTemplate x:Key="HealHealthCell">
			<TextBlock Text="{Binding TotalHealth, StringFormat=N0}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="HealHealsCell">
			<TextBlock Text="{Binding TotalHeals, StringFormat=N0}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="HealHealthPerHealCell">
			<TextBlock Text="{Binding HealthPerHeal, StringFormat=N1}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="HealHPSCell">
			<TextBlock Text="{Binding HealthPerSecond, StringFormat=N1}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<DataTemplate x:Key="HealPercentTotalCell">
			<TextBlock Text="{Binding PercentOfTotalHealing, StringFormat={}{0:N1}%}" HorizontalAlignment="Stretch" TextAlignment="Right" />
		</DataTemplate>

		<GridViewColumnCollection x:Key="HealTypesColumns">
			<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="110" />
			<GridViewColumn Header="Health" CellTemplate="{StaticResource HealHealthCell}" Width="50" />
			<GridViewColumn Header="Heals" CellTemplate="{StaticResource HealHealsCell}" Width="65" />
			<GridViewColumn Header="Health/Heal" CellTemplate="{StaticResource HealHealthPerHealCell}" Width="52" />
			<GridViewColumn Header="Health/Sec" CellTemplate="{StaticResource HealHPSCell}" Width="52" />
			<GridViewColumn Header="% Total" CellTemplate="{StaticResource HealPercentTotalCell}" Width="52" />
		</GridViewColumnCollection>

		<SolidColorBrush x:Key="LightBrush" Color="Black" />

	</UserControl.Resources>

	<DockPanel>

		<StackPanel Orientation="Horizontal" DockPanel.Dock="Top"
					Margin="0,6,0,0">
			<StackPanel.Resources>
				<Style x:Key="DamageSelectorGroupHeaderStyle" TargetType="TextBlock">
					<Setter Property="FontWeight" Value="Bold" />
					<Style.Triggers>
						<DataTrigger Binding="{Binding Name}" Value="True">
							<Setter Property="Text" Value="Mobs" />
						</DataTrigger>
					</Style.Triggers>
				</Style>
			</StackPanel.Resources>

			<TextBlock Margin="13,4,8,4">Character:</TextBlock>
			<ComboBox Name="CharacterSelector"
					  ItemsSource="{Binding Source={StaticResource CharactersSource}}"					  
					  Width="225"
					  IsSynchronizedWithCurrentItem="True">
				<ComboBox.GroupStyle>
					<GroupStyle>
						<GroupStyle.HeaderTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding Name}" Style="{StaticResource DamageSelectorGroupHeaderStyle}" />
							</DataTemplate>
						</GroupStyle.HeaderTemplate>
					</GroupStyle>
				</ComboBox.GroupStyle>

				<ComboBox.ItemTemplate>
					<DataTemplate>
						<StackPanel Orientation="Horizontal">
							<TextBlock Text="{Binding Name}" Width="60" />
							<TextBlock Text="{Binding Offensive_TotalDamage, StringFormat=N0}" Width="60" TextAlignment="Right" />
							<TextBlock Text="{Binding Offensive_DPS, StringFormat=N2}" Width="60" TextAlignment="Right" />
							<TextBlock>/sec</TextBlock>
						</StackPanel>
					</DataTemplate>
				</ComboBox.ItemTemplate>
			</ComboBox>
		</StackPanel>

		<GroupBox x:Name="OffensiveStatsGroup" Header="Offensive Stats" DockPanel.Dock="Top"
				  IsHitTestVisible="False"
				  Margin="4,0,4,2"
				  BorderThickness="1"
				  VerticalAlignment="Top">
			<Grid x:Name="DamageDealtGrid">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="50" />
					<ColumnDefinition Width="70" />
					<ColumnDefinition Width="70" />
				</Grid.ColumnDefinitions>

				<Grid.RowDefinitions>
					<RowDefinition Height="Auto" />
					<!-- Damage -->
					<RowDefinition Height="Auto" />
					<!-- Hits -->
					<RowDefinition Height="Auto" />
					<!-- Crits -->
					<RowDefinition Height="Auto" />
					<!-- Penetrated -->
					<RowDefinition Height="Auto" />
					<!-- Glanced -->
					<RowDefinition Height="Auto" />
					<!-- Blocked -->
					<RowDefinition Height="Auto" />
					<!-- Missed -->
					<RowDefinition Height="Auto" />
					<!-- Absorbed -->
				</Grid.RowDefinitions>

				<TextBlock Text="Total:" Grid.Row="0" Grid.Column="0" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.TotalDamage, StringFormat=N0}" TextAlignment="Right" Grid.Row="0" Grid.Column="1" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.DPS, StringFormat=({0:N1}/min)}" Margin="8,0,0,0" Grid.Row="0" Grid.Column="2" />

				<TextBlock Text="Hits: " Grid.Row="1" Grid.Column="0" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.TotalAttacks, StringFormat=N0}" TextAlignment="Right" Grid.Row="1" Grid.Column="1" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.DamagePerHit, StringFormat=({0:N1}/hit)}" Margin="8,0,0,0" Grid.Row="1" Grid.Column="2" />

				<TextBlock Text="Crits: " Grid.Row="2" Grid.Column="0" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.TotalCrits, StringFormat=N0}" TextAlignment="Right" Grid.Row="2" Grid.Column="1" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.CritPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="2" Grid.Column="2" />

				<TextBlock Text="Penetrated: " Grid.Row="3" Grid.Column="0" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.TotalPenetrated, StringFormat=N0}" TextAlignment="Right" Grid.Row="3" Grid.Column="1" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.PenetratedPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="3" Grid.Column="2" />

				<TextBlock Text="Glanced: " Grid.Row="4" Grid.Column="0" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.TotalGlanced, StringFormat=N0}" TextAlignment="Right" Grid.Row="4" Grid.Column="1" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.GlancedPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="4" Grid.Column="2" />

				<TextBlock Text="Blocked: " Grid.Row="5" Grid.Column="0" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.TotalBlocked, StringFormat=N0}" TextAlignment="Right" Grid.Row="5" Grid.Column="1" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.BlockedPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="5" Grid.Column="2" />

				<TextBlock Text="Missed: " Grid.Row="6" Grid.Column="0" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.TotalEvaded, StringFormat=N0}" TextAlignment="Right" Grid.Row="6" Grid.Column="1" />
				<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=OffensiveHits.EvadedPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="6" Grid.Column="2" />

			</Grid>
		</GroupBox>

		<Expander Header="Attacks" IsExpanded="True" Foreground="White" DockPanel.Dock="Top">
			<StackPanel>
				<GridViewHeaderRowPresenter Columns="{StaticResource AttackTypesColumns}" ColumnHeaderContainerStyle="{StaticResource ColumnsHeaderStyle}" />

				<ItemsControl ItemsSource="{Binding Source={StaticResource CharactersSource}, Path=OffensiveAttackSummaries}"
							  BorderThickness="0">
					<ItemsControl.Template>
						<ControlTemplate>
							<ItemsPresenter />
						</ControlTemplate>
					</ItemsControl.Template>
					<ItemsControl.ItemTemplate>
						<DataTemplate>
							<GridViewRowPresenter Columns="{StaticResource AttackTypesColumns}" />
						</DataTemplate>
					</ItemsControl.ItemTemplate>
				</ItemsControl>

			</StackPanel>
		</Expander>

		<Expander Header="Defensive Stats" IsExpanded="True" Foreground="White" DockPanel.Dock="Top">

			<Border BorderBrush="White" BorderThickness="2" CornerRadius="4" Margin="4,0,0,0" IsHitTestVisible="False">
				<Grid Margin="4">
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="50" />
						<ColumnDefinition Width="70" />
						<ColumnDefinition Width="60" />
					</Grid.ColumnDefinitions>

					<Grid.RowDefinitions>
						<RowDefinition Height="Auto" />
						<!-- Damage -->
						<RowDefinition Height="Auto" />
						<!-- Hits -->
						<RowDefinition Height="Auto" />
						<!-- Crits -->
						<RowDefinition Height="Auto" />
						<!-- Penetrated -->
						<RowDefinition Height="Auto" />
						<!-- Glanced -->
						<RowDefinition Height="Auto" />
						<!-- Blocked -->
						<RowDefinition Height="Auto" />
						<!-- Missed -->
						<RowDefinition Height="Auto" />
						<!-- Absorbed -->
					</Grid.RowDefinitions>

					<TextBlock Text="Damage:" Grid.Row="0" Grid.Column="0" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.TotalDamage, StringFormat=N0}" TextAlignment="Right" Grid.Row="0" Grid.Column="1" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.DPS, StringFormat=({0:N1}/min)}" Margin="8,0,0,0" Grid.Row="0" Grid.Column="2" />

					<TextBlock Text="Hits:" Grid.Row="1" Grid.Column="0" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.TotalAttacks, StringFormat=N0}" TextAlignment="Right" Grid.Row="1" Grid.Column="1" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.DamagePerHit, StringFormat=({0:N1}/hit)}" Margin="8,0,0,0" Grid.Row="1" Grid.Column="2" />

					<TextBlock Text="Crits:" Grid.Row="2" Grid.Column="0" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.TotalCrits, StringFormat=N0}" TextAlignment="Right" Grid.Row="2" Grid.Column="1" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.CritPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="2" Grid.Column="2" />

					<TextBlock Text="Penetrated:" Grid.Row="3" Grid.Column="0" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.TotalPenetrated, StringFormat=N0}" TextAlignment="Right" Grid.Row="3" Grid.Column="1" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.PenetratedPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="3" Grid.Column="2" />

					<TextBlock Text="Glanced:" Grid.Row="4" Grid.Column="0" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.TotalGlanced, StringFormat=N0}" TextAlignment="Right" Grid.Row="4" Grid.Column="1" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.GlancedPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="4" Grid.Column="2" />

					<TextBlock Text="Blocked:" Grid.Row="5" Grid.Column="0" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.TotalBlocked, StringFormat=N0}" TextAlignment="Right" Grid.Row="5" Grid.Column="1" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.BlockedPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="5" Grid.Column="2" />

					<TextBlock Text="Evaded:" Grid.Row="6" Grid.Column="0" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.TotalEvaded, StringFormat=N0}" TextAlignment="Right" Grid.Row="6" Grid.Column="1" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHits.EvadedPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="6" Grid.Column="2" />
				</Grid>
			</Border>
		</Expander>

		<Expander Header="Attacks" IsExpanded="False" Foreground="White" DockPanel.Dock="Top">
			<StackPanel>

				<GridViewHeaderRowPresenter Columns="{StaticResource AttackTypesColumns}" ColumnHeaderContainerStyle="{StaticResource ColumnsHeaderStyle}" />

				<ItemsControl ItemsSource="{Binding Source={StaticResource CharactersSource}, Path=DefensiveAttackSummaries}" Grid.Row="1"
											  BorderThickness="0">
					<ItemsControl.Template>
						<ControlTemplate>
							<ItemsPresenter />
						</ControlTemplate>
					</ItemsControl.Template>
					<ItemsControl.ItemTemplate>
						<DataTemplate>
							<GridViewRowPresenter Columns="{StaticResource AttackTypesColumns}" />
						</DataTemplate>
					</ItemsControl.ItemTemplate>
				</ItemsControl>

			</StackPanel>
		</Expander>

		<Expander Header="Healing" IsExpanded="True" Foreground="White" DockPanel.Dock="Top">
			<Border BorderBrush="White" BorderThickness="2" CornerRadius="4" Margin="4,0,0,0" IsHitTestVisible="False">
				<Grid Margin="4">
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="50" />
						<ColumnDefinition Width="70" />
						<ColumnDefinition Width="70" />
					</Grid.ColumnDefinitions>
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto" />
						<RowDefinition Height="Auto" />
						<RowDefinition Height="Auto" />
					</Grid.RowDefinitions>

					<TextBlock Text="Health:" Grid.Row="0" Grid.Column="0" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHeals.TotalHealth, StringFormat=N0}" TextAlignment="Right" Grid.Row="0" Grid.Column="1" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHeals.HealthPerSecond, StringFormat=({0:N1}/min)}" Margin="8,0,0,0" Grid.Row="0" Grid.Column="2" />

					<TextBlock Text="Heals: " Grid.Row="1" Grid.Column="0" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHeals.TotalHeals, StringFormat=N0}" TextAlignment="Right" Grid.Row="1" Grid.Column="1" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHeals.HealthPerHeal, StringFormat=({0:N1}/heal)}" Margin="8,0,0,0" Grid.Row="1" Grid.Column="2" />

					<TextBlock Text="Crits: " Grid.Row="2" Grid.Column="0" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHeals.TotalCrits, StringFormat=N0}" TextAlignment="Right" Grid.Row="2" Grid.Column="1" />
					<TextBlock Text="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHeals.CritPercent, StringFormat=({0:N1}%)}" Margin="8,0,0,0" Grid.Row="2" Grid.Column="2" />

				</Grid>
			</Border>
		</Expander>

		<Expander Header="Heals" IsExpanded="False" Foreground="White" DockPanel.Dock="Top">
			<StackPanel>

				<GridViewHeaderRowPresenter Columns="{StaticResource HealTypesColumns}" ColumnHeaderContainerStyle="{StaticResource ColumnsHeaderStyle}" />

				<ItemsControl ItemsSource="{Binding Source={StaticResource CharactersSource}, Path=DefensiveHealSummaries}" Grid.Row="1"
											  BorderThickness="0">
					<ItemsControl.Template>
						<ControlTemplate>
							<ItemsPresenter />
						</ControlTemplate>
					</ItemsControl.Template>
					<ItemsControl.ItemTemplate>
						<DataTemplate>
							<GridViewRowPresenter Columns="{StaticResource HealTypesColumns}" />
						</DataTemplate>
					</ItemsControl.ItemTemplate>
				</ItemsControl>

			</StackPanel>
		</Expander>

	</DockPanel>
</UserControl>
